package exercise10;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;


public class Exercise15_03 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        Pane circle_pane=new Pane();
        HBox control_box=new HBox(5);
        BorderPane pane=new BorderPane();

        Circle circle=new Circle();
        circle.setRadius(40);
        circle.setCenterX(200);
        circle.setCenterY(200);
        circle.setFill(new Color(1,1,1,0));
        circle.setStroke(Color.BLACK);

        Button left=new Button("Left");
        Button right=new Button("Right");
        Button up=new Button("Up");
        Button down =new Button("Down");

        control_box.getChildren().addAll(left,right,up,down);
        circle_pane.getChildren().add(circle);

        pane.setCenter(circle_pane);
        pane.setBottom(control_box);

        left.setOnAction(event -> {
            if (circle.getCenterX()>42){
                circle.setCenterX(circle.getCenterX()-2);
            }
        });
        right.setOnAction(event -> {
            if (circle.getCenterX()<358)
            circle.setCenterX(circle.getCenterX()+2);
        });
        up.setOnAction(event -> {
            if (circle.getCenterY()>42){
                circle.setCenterY(circle.getCenterY()-2);
            }
        });
        down.setOnAction(event -> {
            if (circle.getCenterY()<358){
                circle.setCenterY(circle.getCenterY()+2);
            }
        });

        primaryStage.setTitle("可以移动的球");
        primaryStage.setScene(new Scene(pane,400,400));
        primaryStage.show();
    }
}
